package com.gking.processHarvest.controller;

import com.gking.processHarvest.common.Res;
import com.gking.processHarvest.dto.CreateModulesDto;
import com.gking.processHarvest.entity.Module;
import com.gking.processHarvest.service.Module.ModuleService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@Slf4j
@RequestMapping("/module")
public class ModuleController {

    @Autowired
    private ModuleService moduleService;

    /**
     * 批量创建模块
     *
     * @param createModulesDto
     * @return
     */
    @PostMapping("/create")
    public Res<String> createModules(@RequestBody CreateModulesDto createModulesDto) {
        log.warn("project id 为：{}", createModulesDto.getProjectId());
        log.warn("List 列表 为：{}", createModulesDto.getList());
        return moduleService.createModules(createModulesDto.getProjectId(), createModulesDto.getList());
    }


    /**
     * 修改模块信息
     *
     * @param module
     * @return
     */
    @PutMapping("/update")
    public Res<String> updateInfo(@RequestBody Module module) {
        log.warn("传入的要修改模块信息为：{}", module);
        return moduleService.updateInfo(module.getProjectId(), module.getId(), module.getName(), module.getDescription());
    }


    /**
     * 删除模块
     *
     * @param id
     * @return
     */
    @DeleteMapping("/delete/{id}")
    public Res<String> delete(@PathVariable String id) {
        log.warn("要删除的模块 id 为：{}", id);
        return moduleService.delete(id);
    }


    /**
     * 获取项目模块
     *
     * @param projectId 项目id
     * @return s
     */
    @GetMapping("/get/{projectId}")
    public Res<List<Module>> getProjectModules(@PathVariable String projectId) {
        log.warn("要获取模块列表的项目id id 为：{}", projectId);
        if (projectId.equals("")) return Res.error("请将参数补充完整");

        return moduleService.getProjectModules(projectId);
    }
}
